package com.ruoyi.project.dict.kangxianalysis.controller;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.kangxianalysis.domain.KangxiAnalysis;
import com.ruoyi.project.dict.kangxianalysis.service.IKangxiAnalysisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 康熙分析Controller
 *
 * @author shixiangwen
 * @date 2022-06-13
 */
@Controller
@RequestMapping("/dict/kangxianalysis")
public class KangxiAnalysisController extends BaseController {
    private String prefix = "dict/kangxianalysis";

    @Autowired
    private IKangxiAnalysisService kangxiAnalysisService;

    @RequiresPermissions("dict:kangxianalysis:view")
    @GetMapping()
    public String kangxianalysis(ModelMap mmap, String date) {
        if (StringUtils.isEmpty(date)) {
            Date d = DateUtils.addDays(DateUtils.getNowDate(), -1);
            date = DateUtils.dateTime(d);
        }
        mmap.put("date", date);
        return prefix + "/kangxianalysis";
    }

    /**
     * 查询康熙分析列表
     */
    @RequiresPermissions("dict:kangxianalysis:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KangxiAnalysis kangxiAnalysis) {
        startPage();
        List<KangxiAnalysis> list = kangxiAnalysisService.selectKangxiAnalysisList(kangxiAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出康熙分析列表
     */
    @RequiresPermissions("dict:kangxianalysis:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KangxiAnalysis kangxiAnalysis) {
        List<KangxiAnalysis> list = kangxiAnalysisService.selectKangxiAnalysisList(kangxiAnalysis);
        ExcelUtil<KangxiAnalysis> util = new ExcelUtil<KangxiAnalysis>(KangxiAnalysis.class);
        return util.exportExcel(list, "kangxianalysis");
    }

    /**
     * 新增康熙分析
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存康熙分析
     */
    @RequiresPermissions("dict:kangxianalysis:add")
    @Log(title = "康熙分析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KangxiAnalysis kangxiAnalysis) {
        return toAjax(kangxiAnalysisService.insertKangxiAnalysis(kangxiAnalysis));
    }

    /**
     * 修改康熙分析
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        KangxiAnalysis kangxiAnalysis = kangxiAnalysisService.selectKangxiAnalysisById(id);
        mmap.put("kangxiAnalysis", kangxiAnalysis);
        return prefix + "/edit";
    }

    /**
     * 修改保存康熙分析
     */
    @RequiresPermissions("dict:kangxianalysis:edit")
    @Log(title = "康熙分析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KangxiAnalysis kangxiAnalysis) {
        return toAjax(kangxiAnalysisService.updateKangxiAnalysis(kangxiAnalysis));
    }

    /**
     * 删除康熙分析
     */
    @RequiresPermissions("dict:kangxianalysis:remove")
    @Log(title = "康熙分析", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(kangxiAnalysisService.deleteKangxiAnalysisByIds(ids));
    }
}
